// Dynamic convert
// 	basic --->>> subclass

#include <iostream>
using namespace std;

class A {
	virtual void foo( ){}
};
class B : public A {};
class C : public B {};

class D {};

// designer
// ------------------------------------------------------------------
// user

int main( void ) { 
	B b;
	A* pa = &b;	// ok
	cout << "------------ dynamic_cast ------------" << endl;

	B* pb = dynamic_cast<B*>(pa);	// Reasonable and safety
	cout << "A* pa --->>> B* pb : " << pb << endl;

	C* pc = dynamic_cast<C*>(pa);	// Unsafety
	cout << "A* pa --->>> C* pc : " << pc << endl;

	D* pd = dynamic_cast<D*>(pa);	// Unreasonable
	cout << "A* pa --->>> D* pd : " << pd << endl;

	cout << "------------ static_cast ------------" << endl;

	pb = static_cast<B*>(pa);	// Reasonable and safety
	cout << "A* pa --->>> B* pb : " << pb << endl;

	pc = static_cast<C*>(pa);	// Unsafety
	cout << "A* pa --->>> C* pc : " << pc << endl;

//	pd = static_cast<D*>(pa);	// Unreasonable
//	cout << "A* pa --->>> D* pd : " << pd << endl;

	return 0;
}

